{{ template "layout/adminheader" .}}
<main id="body">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <form action="#" method="post" id="form">
                            <h4 class="card-title">编辑 - {{.forum.Name}}</h4>
                            <input type="hidden" name="id" id="id" value="{{.forum.ID}}">
                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" for="name">名称：</label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" id="name" placeholder="" value="{{.forum.Name}}" class="form-control">
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" for="name">排序：</label>
                                <div class="col-sm-3">
                                    <input type="text" name="rank" id="rank" placeholder="" value="{{.forum.Rank}}" class="form-control">
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" for="brief">简介：</label>
                                <div class="col-sm-10">
                                    <textarea name="brief" id="brief" class="form-control" style="width: 100%; height: 80px; ">{{.forum.Brief}}</textarea>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" for="announcement">公告：</label>
                                <div class="col-sm-10">
                                    <textarea name="announcement" id="announcement" class="form-control" style="width: 100%; height: 80px; ">{{.forum.Announcement}}</textarea>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" for="moduids">版主：</label>
                                <div class="col-sm-10">
                                    <input type="text" name="moduids" id="moduids" placeholder="" value="{{.forum.Moduids}}" class="form-control">
                                    <p class="small text-muted mt-2" id="modnames">最多允许10个，逗号隔开，如：Jack,Lisa,Mike</p>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" for="seotitle">SEO关键词：</label>
                                <div class="col-sm-10">
                                    <input type="text" name="seotitle" id="seotitle" placeholder="" value="{{.forum.SeoTitle}}" class="form-control">
                                    <p class="small text-muted mt-2" id="modnames">最多允许10个，逗号隔开，如：Jack,Lisa,Mike</p>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label" >启用标签：</label>
                                <div class="col-sm-10">
                                    <ul id="tagcatelist" class="list-unstyled threadlist mb-0">
                                        {{$usetag := .usetags}}
                                        {{range .tagcate}}
                                            {{$id := .ID}}
                                        <li class="media thread tap top_3 ">
                                            <input type="checkbox" name="tagcate" class="mt-3 mr-2" value="{{.ID}}"  {{range $usetag}} {{if eq .TagCateID $id}}checked{{end}}{{end}}>
                                            {{/*<input type="checkbox" name="tagcate" class="mt-3 mr-2" value="{{.ID}}"  {{range $usetag}} {{if eq .TagID $id}}checked{{end}}{{end}}>*/}}
                                            <div class="media-body">
                                                <div class="subject break-all">
                                                    <a><span class="huux_thread_hlight_style2">{{.Name}}</span></a>
                                                </div>
                                                <div class="d-flex justify-content-between small mt-1">
                                                    <div>
                                                        {{range .Tags}}
                                                        <span class="username text-grey mr-1  hidden-sm" uid="2">{{.Name}}</span>
                                                        {{end}}
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                        {{end}}
                                    </ul>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label"></label>
                                <div class="col-sm-10">
                                    <button type="button" class="btn btn-primary btn-block" id="submit" data-loading-text="正在提交..." default-text="确定">确定</button>
                                    <button type="button" class="btn btn-secondary btn-block mt-3" onclick="javascript:history.back();">返回</button>
                                </div>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

<script>
    var jsubmit = $("#submit");
    jsubmit.on('click', function () {
        var id              = $("#id").val()
        var name            = $("#name").val()
        var rank            = $("#rank").val()
        var brief           = $("#brief").val()
        var announcement    = $("#announcement").val()
        var moduids         = $("#moduids").val()
        var seotitle        = $("#seotitle").val()
        var tidarr          = $("#tagcatelist").find('input[name="tagcate"]').checked();
/*        console.log("获取的数组",tidarr)
        return*/

        var fd = new FormData()
        fd.append("id", id)
        fd.append("name", name)
        fd.append("rank", rank)
        fd.append("brief", brief)
        fd.append("announcement", announcement)
        fd.append("moduids", moduids)
        fd.append("seo_title", seotitle)
        fd.append("tidarr", tidarr)

        $.ajax({
            url: "/admin/forum/update?token="+admintoken,
            data: fd,
            type: "POST",
            contentType: false,
            processData:false,
            success: function(res) {
                //成功
                console.log(res)
                // return;

                if (res.code == 200) {
                    $.alert("修改成功")
                    setTimeout(function(){
                        location.href="/admin/forum_list.html?token="+admintoken
                    }, 2000)
                }
            },
            error: function() {
                //失败
            }
        })
    });

</script>

<script>
    $('#nav li.nav-item-forum').addClass('active');
</script>

{{ template "layout/adminfooter" .}}